package cn.steam.service;

import cn.steam.xo.TokenVO;
import org.springframework.stereotype.Component;

/**
 * @author zhang jintao on 2022/08/01
 **/
@Component
public class TokenService {

    public static final InheritableThreadLocal<TokenVO> TOKEN_THREAD_LOCAL = new InheritableThreadLocal<>();

    public void set(TokenVO tokenVO) {
        TOKEN_THREAD_LOCAL.set(tokenVO);
    }

    public TokenVO get() {
        TokenVO vo = TOKEN_THREAD_LOCAL.get();
        if (vo == null) {
            throw new RuntimeException("获取token异常");
        }
        return vo;
    }

    public void remove() {
        TOKEN_THREAD_LOCAL.remove();
    }

}
